// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-09-13 22:53:18
 * @LastEditors: qiulin ql1746365080@gmail.com
 * @LastEditTime: 2024-12-12 15:11:42
 * @FilePath: \SGFEM\Import\NastranBDF\test\Element\CPYRAMParserTest.cpp
 */

#include "Import/BDFImport/BulkData/Element/CPYRAMParser.h"

#include "gtest/gtest.h"

#include "DataStructure/Input/Element/CPYRAMData.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class CPYRAMParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (CPYRAMParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "CPYRAM         9       2      23      22      21      18      20" };

    SG::DataStructure::FEM::CPYRAM5Data data;
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCPYRAM (DB_SERVICEFACTORY, dividedEntryInfo);

    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);

    ASSERT_TRUE (data.m_id == 9);
    ASSERT_TRUE (data.m_pId == 2);
    ASSERT_TRUE (data.m_g[0] == 23);
    ASSERT_TRUE (data.m_g[1] == 22);
    ASSERT_TRUE (data.m_g[2] == 21);
    ASSERT_TRUE (data.m_g[3] == 18);
    ASSERT_TRUE (data.m_g[4] == 20);
}

TEST_F (CPYRAMParserTest, ParseEntry2)
{
    std::vector<std::string> Entry = { "CPYRAM         1       2       3       1       2       5      12       6+0000061",
                                       "+0000061       4       9      13      25       7      10      26" };

    SG::DataStructure::FEM::CPYRAM13Data data;
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCPYRAM (DB_SERVICEFACTORY, dividedEntryInfo);

    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);

    ASSERT_TRUE (data.m_id == 1);
    ASSERT_TRUE (data.m_pId == 2);
    ASSERT_TRUE (data.m_g[0] == 3);
    ASSERT_TRUE (data.m_g[1] == 1);
    ASSERT_TRUE (data.m_g[2] == 2);
    ASSERT_TRUE (data.m_g[3] == 5);
    ASSERT_TRUE (data.m_g[4] == 12);
    ASSERT_TRUE (data.m_g[5] == 6);
    ASSERT_TRUE (data.m_g[6] == 4);
    ASSERT_TRUE (data.m_g[7] == 9);
    ASSERT_TRUE (data.m_g[8] == 13);
    ASSERT_TRUE (data.m_g[9] == 25);
    ASSERT_TRUE (data.m_g[10] == 7);
    ASSERT_TRUE (data.m_g[11] == 10);
    ASSERT_TRUE (data.m_g[12] == 26);
}